package com;

import java.util.HashMap;

import database.databaseInteraction;
import database.database_auth;
import com.database.databaseElement;

/** defines a message **/
public class message extends databaseElement {

/** message format (could be outdated) 
CREATE TABLE IF NOT EXISTS `communication` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MESSAGEID` bigint(20) unsigned NOT NULL,
  `subject` text NOT NULL,
  `discussionParentID` bigint(20) NOT NULL DEFAULT '0',
  `fromUserID` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the sender of the message',
  `toUserID` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a user than this is his ID, otherwise it is 0',
  `toGroupID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a group than this is his ID, otherwise it is 0',
  `toDiscussionID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a discussion than this is his ID, otherwise it is 0',
  `toProjectID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a project than this is his ID, otherwise it is 0',
  `timeSend` bigint(20) NOT NULL DEFAULT '0',
  `status` text NOT NULL COMMENT 'read, unread, deleted, spam',
  `text` text NOT NULL,
  `spam` bigint(20) NOT NULL DEFAULT '0' COMMENT 'defines the spam score/ranking of a message, it should be setable in the options how many people need to mark a message as spam to treat the message as spam',
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

**/
//	  `toUserID` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a user than this is his ID, otherwise it is 0',
	public String toUserID = "";
//	  `toGroupID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a group than this is his ID, otherwise it is 0',
	public String toGroupID = "";
//	  `toDiscussionID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a discussion than this is his ID, otherwise it is 0',
	public String toDiscussionID = "";
//	  `toProjectID` bigint(20) NOT NULL DEFAULT '0' COMMENT 'if this message is addressed to a project than this is his ID, otherwise it is 0',
	public String toProjectID = "";
//    `fromUserID` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the sender of the message',
	public String fromUserID = "";
	public String message = "";
	public String MESSAGEID = "";
	public String ChatSessionID = "";
	public String subject = "";
	public discussion DISCUSSION = null; // contains discussionParentID, toDiscussionID == ID of the discussion
	public String timeStarted = ""; // timeStamp in MS since 1.1.1970 when the discussion / message was started
	public String timeFinished = ""; // timeStamp in MS since 1.1.1970 when the discussion / message was started
	public String timeSend = ""; // timeStamp in MS since 1.1.1970 when the discussion / message was send
	public String status = ""; // read, unread, deleted
//	   `spam` bigint(20) NOT NULL DEFAULT '0' COMMENT 'defines the spam score/ranking of a message, it should be setable in the options how many people need to mark a message as spam to treat the message as spam',
	public String spam = ""; // read, unread, deleted, spam

	databaseInteraction DatabaseConnection = new databaseInteraction();

	public message(database_auth database_auth_inst) 
	{
		super(database_auth_inst, "communication", "MESSAGEID");
		
		DISCUSSION = new discussion(database_auth_inst, this);

		if(!DISCUSSION.name.equals(""))
		{
			// check if the discussion allready exists, if not create it
			DISCUSSION.createDiscussion();
		}
	}
}